<template>
  <div class="container">
    <ListTitle ref="listTitle" :list-title="functionName"></ListTitle>
    <!-- 查询 -->
    <div ref="searchFrom" class="search-from">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
        <template v-for="query in querys">
          <el-form-item label="许可时间" prop="licenseTime" v-if="query.prop === 'licenseTime' && query.show">
            <el-date-picker
              style="width: 140px"
              v-model="queryParams.startTime"
              value-format="yyyy-MM-dd"
              placeholder="开始时间"
            ></el-date-picker>
            <span class="connect">至</span>
            <el-date-picker
              v-model="queryParams.endTime"
              style="width: 140px"
              value-format="yyyy-MM-dd"
              placeholder="结束时间"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="归属区" prop="belongingArea" v-if="query.prop === 'belongingArea' && query.show">
            <el-select v-model="queryParams.belongingArea" placeholder="归属区" clearable>
              <el-option
                v-for="dict in dict.type.basic_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="状态" prop="status" v-if="query.prop === 'status' && query.show">
            <el-select v-model="queryParams.status" placeholder="请选择企业状态" clearable>
              <el-option
                v-for="dict in dict.type.basic_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </template>
        <el-form-item>
          <el-button size="mini" @click="resetQuery">重置</el-button>
          <el-button type="primary" size="mini" @click="handleQuery">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 列表 -->
    <div class="table">
      <div class="table-container" style="min-height: 0">
        <el-table height="100%" v-loading="loading" :data="dataList" stripe highlight-current-row>
          <el-table-column label="#" type="index" width="50" align="center"/>
          <template v-for="column in columns">
            <el-table-column
              v-if="column.show"
              :key="column.prop"
              :prop="column.prop"
              :label="column.label"
              :width="column.width"
              :resizable="column.resizable"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <span v-if="column.prop === 'effectiveTime'">{{ scope.row.startTime }} - {{ scope.row.endTime }}</span>
                <span v-else-if="column.prop === 'status'">
                <dict-tag :options="dict.type.basic_status" :value="scope.row[column.prop] "/>
              </span>
                <span v-else>{{ scope.row[column.prop] }}</span>
              </template>
            </el-table-column>
          </template>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleDetail(scope.row)"
              >详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!-- 分页 -->
    <div ref="pagination" class="bottom-pagination">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        layout="sizes, total, prev, pager, next, jumper"
        @pagination="getList"
      />
    </div>
    <!-- 详情 -->
    <el-dialog :visible.sync="open" class="dialog" center width="65%" append-to-body :show-close="false"
               destroy-on-close>
      <template slot="title">
        <div class="dialog-header">
          <span class="header-title">{{ dialogTitle }}</span>
          <i class="el-icon-circle-close close-icon" @click="open = false"></i>
        </div>
      </template>
      <el-form ref="form" :model="form" :inline="true" label-position="right" label-width="80px">
        <el-row :gutter="20" type="flex" justify="space-between">
          <el-col :span="10">
            <el-form-item label="企业许可证" prop="licenseCode">
              <el-input :value="form.licenseCode"/>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="企业联系人" prop="contacts">
              <el-input :value="form.contacts"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" type="flex" justify="space-between">
          <el-col :span="10">
            <el-form-item label="联系方式" prop="contactInfo">
              <el-input :value="form.contactInfo"/>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="企业地址" prop="contactAddress">
              <el-input :value="form.contactAddress"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" type="flex" justify="space-between">
          <el-col :span="10">
            <el-form-item label="起止时间">
              <el-input :value="form.startTime + ' - ' + form.endTime "/>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="企业状态" prop="status">
              <el-select :value="form.status" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.basic_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="企业许可证" prop="picUri">
              <div class="pic">
                <el-image
                  v-if="form.picUri"
                  :src="form.picUri"
                  :preview-src-list="[form.picUri]">
                  <div slot="error"></div>
                </el-image>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
// import store from "@/store";
// import {listDynamicSettings} from "@/api/basicInfo/basic";
import ListTitle from './ListTitle';

export default {
  name: "Enterprise",
  components: {ListTitle},
  dicts: ['basic_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 10,
      // 数据列表
      dataList: [],
      // 弹出层标题
      dialogTitle: "",
      // 是否显示弹出层
      open: false,
      fieldCustomOpen: false,
      dynamicSettingsId: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startTime: undefined,
        endTime: undefined,
        belongingArea: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      functionId: "enterprise",
      functionName: "企业档案",
      // 查询参数
      querys: [],
      // 列信息
      columns: [],
      dict: {
      type: {
        basic_status: [
          { value: 'active', label: 'Active' },        // 状态为"active"的企业
          { value: 'inactive', label: 'Inactive' },    // 状态为"inactive"的企业
          { value: 'pending', label: 'Pending' },      // 状态为"pending"的企业
          { value: 'suspended', label: 'Suspended' }   // 状态为"suspended"的企业
        ],
        belonging_area: [
          { value: 'north', label: 'Northern Region' },  // 北区
          { value: 'south', label: 'Southern Region' },  // 南区
          { value: 'east', label: 'Eastern Region' },    // 东区
          { value: 'west', label: 'Western Region' }     // 西区
        ],
        enterprise_type: [
          { value: 'private', label: 'Private' },        // 私营企业
          { value: 'state', label: 'State-owned' },      // 国有企业
          { value: 'foreign', label: 'Foreign' },        // 外资企业
          { value: 'joint', label: 'Joint venture' }     // 合资企业
        ]
      }
    },
    };
  },
  created() {
    this.initColumns();
    this.initQuerys();
    this.getList();
  },
  methods: {
    /** 初始化查询字段 */
    initQuerys() {
      this.querys = [
        {key: 0, label: `许可时间`, prop: 'licenseTime', show: true},
        {key: 1, label: `归属区`, prop: 'belongingArea', show: true},
        {key: 2, label: `状态`, prop: 'status', show: true}
      ]
    },
    /** 初始化列表字段 */
    initColumns() {
      this.columns = [
        {key: 0, label: `企业编号`, prop: 'enterpriseNo', show: true},
        {key: 1, label: `企业名称`, prop: 'enterpriseName', show: true},
        {key: 2, label: `联系方式`, prop: 'contactInfo', show: true},
        {key: 3, label: `联系人`, prop: 'contacts', show: true},
        {key: 4, label: `联系地址`, prop: 'contactAddress', show: true},
        {key: 5, label: `注册地址`, prop: 'registeredAddress', show: true},
        {key: 6, label: `邮箱`, prop: 'email', show: false},
        {key: 7, label: `经营许可证编号`, prop: 'licenseCode', show: false},
        {key: 8, label: `经营许可证有效时间`, prop: 'effectiveTime', show: false},
        // {label: `经营许可证有效开始时间`, prop: 'startTime', show: true },
        // {label: `经营许可证有效结束时间`, prop: 'endTime', show: true },
        {key: 9, label: `许可证图片`, prop: 'picUri', show: false},
        {key: 10, label: `企业状态`, prop: 'status', show: false}
      ]
    },
    /** 查询企业档案列表 */
    getList() {
      this.loading = true;
      this.dataList = [
        {
          enterpriseNo: "JG08820",
          enterpriseName: "中航金城无人系统有限公司",
          contacts: "赵来景",
          contactsType: "17621234567",
          contactsAddress: "南京市秦淮区龙蟠中路216号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        },
        {
          enterpriseNo: "QYBH537",
          enterpriseName: "XXXXXXXXXX企业",
          contacts: "张三",
          contactsType: "1762123456",
          contactsAddress: "琴新区环岛东路3018号",
          enterpriseLicense: "2024/07/28-2027/07/28"
        }
      ];
      this.loading = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        enterpriseNo: undefined,
        enterpriseName: undefined,
        contacts: undefined,
        contactInfo: undefined,
        contactsAddress: undefined,
        startTime: undefined,
        endTime: undefined,
        status: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.startTime = undefined;
      this.queryParams.endTime = undefined;
      this.handleQuery();
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.open = true;
      this.dialogTitle = row.enterpriseName;
      this.form = row;
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../assets/demo/index.scss";
</style>
<style lang="scss" scoped>
.table {
  height: 100%;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;

  .table-container {
    flex: 1 1 auto;
    height: 70vh;
  }
}


</style>
